import os
import re
import sys

NameList= os.listdir('FILE')
map1={}
for x in NameList:
	with open('FILE/'+x)as f:
	        lines=f.read()
		keys=re.split('[,.\n ;:!?]',lines)
		keys=filter(lambda y:False if y=='' else True,keys)
		keys=map(lambda y: y.lower(),keys)
		sentences=re.split('[.!;?]',lines)
		sentences=map(lambda y: y.strip(),sentences)
		sentences=filter(lambda y:False if y in ['','\n',' ']else True,sentences)
		
		for y in keys:
			if y not in map1.keys():
		        	s_num=[(x,i) for i in range(len(sentences)) if y in sentences[i].lower()]
				map1[y]=list(set(s_num))
			else:
		        	s_num=[(x,i) for i in range(len(sentences)) if y in sentences[i].lower()]
				map1[y].extend(s_num)
				map1[y]=list(set(map1[y]))
		print sentences
		print '-----------------------'


print'******************************************************'
print map1
print '*******************************************************'
print map1[sys.argv[1].lower()]

print "\n----------------------------\n"

for x,y in map1[sys.argv[1].lower()]:
	with open('FILE/'+x)as f:
		lines=f.read()
		sentences=re.split('[.!;?]',lines)
		sentences=map(lambda y: y.strip(),sentences)
		sentences=filter(lambda y:False if y in ['','\n',' ']else True,sentences)
	        print sentences[y]
                print "--------------"
                print '\n'


#print ([1,2,3],[4,5,6])
